package com.gxa.service.Impl;

import com.gxa.common.base.LayuiResultJson;
import com.gxa.common.base.Result;
import com.gxa.common.constant.Constants;
import com.gxa.domain.entity.PayProject;
import com.gxa.mapper.PayProjectMapper;
import com.gxa.service.PayProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PayProjectServiceImpl implements PayProjectService {
    @Autowired
    private PayProjectMapper payProjectMapper;
    public PayProject findPayProjectById(int payProjectId){
        PayProject payProject = new PayProject();
        payProject = payProjectMapper.queryById(payProjectId);
        System.out.println("查询的payProject："+payProject);
        return payProject;
    }

    @Override
    public List<PayProject> queryAll() {
        return payProjectMapper.queryAll();
    }

//    @Override
//    public LayuiResultJson queryPage(int page, int size) {
//        Integer offset = (page - 1)*page;
//        Integer rows = size;
//        List<PayProject> payProjects = payProjectMapper.queryPage(offset, rows);
//        LayuiResultJson layuiResultJson = new LayuiResultJson();
//        layuiResultJson.setCode(Constants.OK);
//        layuiResultJson.setMsg(Constants.MESSAGE_OK);
//        layuiResultJson.setData(payProjects);
//        layuiResultJson.setCount(payProjectMapper.countPayProject());
//        System.out.println("pay分页查询："+layuiResultJson);
//
//        return layuiResultJson;
//    }

    @Override
    public void updateById(Long id, String columnName) {
        payProjectMapper.updateById(id, columnName);
    }

//    @Override
//    public void deleteById(Long id) {
//        payProjectMapper.deleteById(id);
//    }

    @Override
    public void insert(PayProject payProject) {
        payProjectMapper.add(payProject);
    }

    @Override
    public LayuiResultJson queryPayById(String id,int page,int size) {

        Integer offset = (page - 1)*page;
        Integer rows = size;
        List<PayProject> payProjects = payProjectMapper.queryPayById(id,offset, rows);
        LayuiResultJson layuiResultJson = new LayuiResultJson();
        layuiResultJson.setCode(Constants.OK);
        layuiResultJson.setMsg(Constants.MESSAGE_OK);
        layuiResultJson.setData(payProjects);
        layuiResultJson.setCount(payProjectMapper.countPayProject());
        System.out.println("pay分页查询："+layuiResultJson);

        return layuiResultJson;
    }

    @Override
    public Result queryPayByIds(List<PayProject> payProjects) {
        for (PayProject payProject:payProjects){
            payProjectMapper.deleteById(payProject.getId());
        }

        return Result.success(Constants.OK,Constants.MESSAGE_OK);
    }
}
